package cj.web.admin.controllers;

import java.util.EnumSet;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import cj.utils.Constants;
import cj.utils.DateUtils;
import cj.web.admin.constants.KDAddressAreaEnum;
import cj.web.admin.constants.KDAddressStreetEnum;
import cj.web.admin.constants.KDBookingStatusEnum;
import cj.web.admin.constants.KDInTypeEnum;
import cj.web.admin.constants.MemuEnum;
import cj.web.admin.dao.KDAdviseDAO;
import cj.web.admin.domain.KDAdvise;
import cj.web.admin.domain.KDBookingCard;
import cj.web.login.controllers.BaseController;

@Path("/kdadvise")
public class KDAdviseController extends BaseController{

	private static Logger logger = Logger.getLogger(KDAdviseController.class.getName());
	
	@Autowired
	private KDAdviseDAO kDAdviseDao;
	
	@Get("show")
	public String show(Model model,KDAdvise kDAdvise) {
		//MemuEnum
        model.add("MemuEnum",MemuEnum.kdgstsjy);
        
        model.add("kdBookingStatusEnum",EnumSet.allOf(KDBookingStatusEnum.class));
        model.add("kdInTypeEnum",EnumSet.allOf(KDInTypeEnum.class));
        return "portal/kdAdviseList.vm";
	}

	@Post("getList")
	public String queryList(KDAdvise kdAdvise) {
	
		JSONObject jo = new JSONObject();
		
		List<KDAdvise> objs = kDAdviseDao.query(kdAdvise);
		
		for(KDAdvise obj:objs)
		{
			obj.setCreateAT(DateUtils.getMinusTime(obj.getCreateAT(), DateUtils.DATE_FULL_STR, 0));
		}
		
		int size = kDAdviseDao.querySize(kdAdvise);
		
		jo.put("data", objs);
		jo.put("draw", kdAdvise.getDraw());
		jo.put("recordsTotal", size);
		jo.put("recordsFiltered", size);
		return "@"+jo.toString();
	}
	
	@Get("edit")
	public String edit(Model model,@Param("id") int id)
	{
		//MemuEnum
        model.add("MemuEnum",MemuEnum.kdgsdbkqy);
        
        KDAdvise obj = kDAdviseDao.queryById(id);
		model.add("obj", obj);
		
		return "portal/kdAdviseEdit.vm";
	}
	
	@Post("update")
	public String update(Model model,KDAdvise kdAdvise,HttpServletRequest request)
	{
		kDAdviseDao.updateMemoById(kdAdvise.getId(), kdAdvise.getMemo());
		return "r:show";
	}
	
	@Get("updateStatus")
	public String updateStatus(Model model,@Param("id") int id)
	{
		kDAdviseDao.updateStatusById(id);
		return "r:show";
	}
	
	@Get("deleteById")
	public String deleteById(Model model,@Param("id") int id)
	{
		kDAdviseDao.deleteById(id);
		return "r:show";
	}
}
